<template>
  <div class="app-container">
    <!-- 表格-条件筛区域  -->
    <div class="filter-container">
      <el-input v-model="searchParam.SEARCH_LIKE_rolename" placeholder="请输入关键字" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>

    <!-- 表格-内容区域 -->
    <el-table :key="tableKey" v-loading="listLoading" :data="tableList" border fit highlight-current-row style="width: 100%;">

      <el-table-column
        v-for="column in columns"
        :key="column.prop"
        :prop="column.prop"
        :label="column.label"
        :width="column.width"
        :align="column.align?column.align:'center'"
        :min-width="column.minWidth"
        :sortable="column.sortable"
        :fixed="column.fixed"
        :type="column.type"
        :formatter="column.formatter"
      >
        <template slot-scope="scope">
          <img v-if="column.imgFlag==true" :src="CMBASE.baseFileContext + scope.row[column.prop]" width="60" height="60" class="img">
          <span v-else-if="column.formatter"> {{ column.formatter(scope.row) }}</span>
          <span v-else>{{ scope.row[column.prop] }}</span>
        </template>

      </el-table-column>

    </el-table>

    <!-- 表格-页脚区域 -->
    <pagination v-show="tableTotal>0" :total="tableTotal" :page.sync="pageRequest.pageNum" :limit.sync="pageRequest.pageSize" @pagination="getList" />

  </div>
</template>

<script>

import waves from '@/directive/waves' // Waves directive
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import { getSysLogList } from '../../api/modules/cm-system'
export default {
  name: 'ProductBrand',
  components: { Pagination },
  directives: { waves },
  filters: { },
  data() {
    return {
      tableKey: 0,
      tableList: [], // 表格数据源
      tableTotal: 0, // 表格总条数数据
      listLoading: true,
      pageRequest: { pageNum: 1, pageSize: 10 },
      searchParam: { SEARCH_LIKE_rolename: '' },
      dialogFormVisible: false, // 默认不显示弹出框
      operation: true, // true:新增, false:编辑
      editLoading: false, // 保存表单时loading框
      columns: [
        { prop: 'username', label: '用户名', sortable: false },
        { prop: 'operation', label: '用户操作', sortable: false },
        { prop: 'method', label: '请求方法', sortable: false, width: '500' },
        { prop: 'time', label: '响应时间(ms)', sortable: false },
        { prop: 'ip', label: 'IP地址', sortable: false },
        { prop: 'cTime', label: '请求时间', sortable: false }
      ]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取表格数据
    getList() {
      this.listLoading = true
      // 【API请求】----获取用户列表数据
      getSysLogList(this.pageRequest).then(response => {
          this.tableList = response.result.content
          this.tableTotal = response.result.total
          this.listLoading = false
      }).catch((res) => {
        this.$message({ message: '用户列表获取失败', type: 'error' })
      })
    },
    // 表格数据筛选
    handleFilter() {
      this.pageRequest.searchParam = this.searchParam
      this.getList()
    }
  }
}
</script>
